package com.kafka.example.kafka.service;

import java.util.Date;

import com.kafka.example.kafka.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author CodeDancing
 * @version 1.0
 * @date 2022/2/17 3:42 下午
 */
@Component
public class KafkaSender {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    /**
     	* 发送消息到kafka,主题为mainboot
     */
    public void sendMessage(){
        kafkaTemplate.send("topic01","hello,kafka!"  + DateUtils.formatDate(new Date()));
    }
}